// TClientRobot.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Log/Log.h"
#include "Log/LogInitializer.h"
#include "Service/ServiceImpCli.h"
#include "Service/ServiceImpNW.h"
#include "Service/ServiceDataCli.h"
#include "Message/MsgLuaCommand.h"
#include "Lua/LuaWrapper.h"
#include "UserData/UserDataLua.h"
#include "Entry/MainLua.h"


int _tmain(int argc, _TCHAR* argv[])
{
	woe::Properties props;
	if (!props.init("TClientRobot.properties"))
	{
		std::cout<<"Failed to load properties file!, Invalid properties file!"<<endl;
		return 0;
	}
	woe::LogInitializer __init(props);


	//	for test
	ServiceImpNW	svcNW;
	ServiceImpCli	svcCli;
	ServiceDataCli	data(&svcNW, &svcCli, &props);

	UserDataLua::instance()->wpSvcLgc = & svcCli;
	UserDataLua::instance()->wpSvcNet = & svcNW;
	UserDataLua::instance()->initialize();
	MainLua::libaray(Lua::instance()->state());

	svcNW.init(data);
	svcCli.init(data);

	svcNW.start();
	svcCli.start();


	char szCommand [1024];
	while(true)
	{
		cin.getline(szCommand, 1024);

		if (strlen(szCommand)>0)
		{
			if (strcmp(szCommand, "quit")==0 || strcmp(szCommand, "quit()")==0)
			{
				LOG_INFO("Trying to quit... ...!");
				svcNW.stop();
				svcCli.stop();
				break;
			}
			else
			{
				svcCli.postMsg(new MsgLuaCommand(szCommand));
			}
		}
	}

	svcNW.wait();
	svcCli.wait();

	
	return 0;
}

